// JavaScript Document
//-------------------------------------------
//fja koja omogucava editovanje mere
function changeEdit_RadniciIO(id){
	
	obj_radio= document.getElementById("r_"+id);	
	
	//alert('edit:'+id+obj_radio.value);

	obj_p_id= document.getElementById("polje_id_"+id);

	
	obj_p_ime= document.getElementById("polje_ime_"+id);

	
	//obj_p_percent= document.getElementById("polje_percent_"+id);

	
	obj_save_button= document.getElementById("save_"+id);
	obj_delete_button= document.getElementById("delete_"+id);
	obj_edit_button= document.getElementById("edit_"+id);
	/*		
	obj_edit_button.innerHTML='<img src="gui/icons/cancel.gif" alt="" />';
	obj_edit_button.obj = tmpEditHldr;
	//obj_edit_button.xid = id;
	obj_edit_button.onclick = function(){
	this.obj.innerHTML = tmpBuffer[id];
	this.innerHTML = '<img src="gui/icons/edit.gif" alt="" />';
	*/
	if(obj_radio.value=="0"){
		p_id_val= obj_radio.value;
		p_ime_val= obj_p_ime.value;
		//p_percent_val= obj_p_percent.value;
		
		obj_radio.value="1";
		
		obj_p_ime.disabled= false;
		//obj_p_percent.disabled= false;
		
		obj_save_button.style.visibility="visible";
		obj_delete_button.style.visibility="visible";
		
		obj_edit_button.innerHTML='<img src="gui/icons/cancel.gif" alt="" />';
			

		}
	else{	

		obj_radio.value="0";
		obj_p_ime.disabled= true;
		obj_p_ime.value= p_ime_val;		
		
		//obj_p_percent.disabled= true;
		//obj_p_percent.value= p_percent_val;		
		
		obj_save_button.style.visibility="hidden";
		obj_delete_button.style.visibility="hidden";
			
		obj_edit_button.innerHTML='<img src="gui/icons/edit.gif" alt="" />';
		

	}
}
//-------------------------------------------
//izmeni vrednost polja (select lista) i prikaze delatnosti iz selektovanog polja (kategorija_id)
function changeVal_RadniciIO(obj){
	broj = obj.options[obj.selectedIndex].value;
	LoadRSDoc('radnici_io.php?a=show&i='+broj,'setContent');
	//alert(listText);
}
//-------------------------------------------
//prikaz delatnosti po kategoriji id
//prikaz delatnosti za zadato id- kategorija ID
function show_RadniciIO(id){
	//alert(id);
	LoadRSDoc('radnici_io.php?a=show&i='+id,'setContent');
}
//-------------------------------------------
//cuva izmene u polju
function saveChanges_RadniciIO(id){
	//alert(id);
	obj_radio= document.getElementById("r_"+id);
	obj_id= document.getElementById("polje_id_"+id);
	obj_p_ime= document.getElementById("polje_ime_"+id);
	//obj_p_percent= document.getElementById("polje_percent_"+id);

	obj_save_button= document.getElementById("save_"+id);
	
	param='radnici_io.php?a=save&i='+obj_id.value+'&name='+obj_p_ime.value;
	//alert(param);
	if(confirm('Da li želite da izmenite polje: '+obj_p_ime.value+' ?'))
		LoadRSDoc( param , 'refresh_RadniciIO(0,obj_p_id.value)');
}
//-------------------------------------------
//osvezava prikaz mera
function refresh_RadniciIO(requestResponse, id){
	param="";
	//alert(requestResponse);
	//return;
	if(id){
		param+='&i='+id;
	}
	
	LoadRSDoc('radnici_io.php?a=show'+param,'setContent');
}
//-------------------------------------------
//otvara stranu <strana> rezultata mera
function open_RadniciIO( strana){
	param="";
	if(strana){
		param+='&s='+strana;
	}
	LoadRSDoc('radnici_io.php?a=show'+param,'setContent');
}
//--------------------------------------------
//omogucava unos nove mere
function new_RadniciIO(){
	obj_new= document.getElementById("polje_new");
	obj_new.style.display = "block";
	obj_enter= document.getElementById("polje_ime_new");
	obj_enter.focus();
	obj_enter.select();
}

//--------------------------------------------
//dodaje novu meru
function add_RadniciIO(){
	obj_p_ime= document.getElementById("polje_ime_new");
	//obj_p_percent= document.getElementById("polje_percent_new");
	
	param='radnici_io.php?a=add&name='+obj_p_ime.value;
	//alert(param);
	//if(confirm('Da li želite da unesete polje: '+obj_p_ime.value+' ?')){
		LoadRSDoc(param,'refresh_RadniciIO()');
		//LoadRSDoc(param,'setContent');
		LoadRSDoc('radnici_io.php?a=show','refresh_RadniciIO()');
	//}
	//LoadRSDoc('radnici_io.php?a=show&i='+id,'refresh_RadniciIO');
}

//-------------------------------------------
//brise meru ID
function del_RadniciIO(id){
	obj_radio= document.getElementById("r_"+id);
	obj_p_ime= document.getElementById("polje_ime_"+id);
	obj_p_id= document.getElementById("polje_id_"+id);

	obj_p_percent= document.getElementById("polje_percent_"+id);

	param='radnici_io.php?a=del&i='+obj_p_id.value+'&name='+obj_p_ime.value;
	//alert(param);
	//LoadRSDoc(param,'setContent');
	if(confirm('Da li želite da izbrišete polje: '+obj_p_ime.value+' ?'))
		LoadRSDoc( param , 'refresh_RadniciIO(obj_p_id.value)');
}